package com.kcwx.common.core.domain.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.kcwx.common.core.domain.entity.SysMenu;
import com.kcwx.common.utils.StringUtils;

import lombok.Data;

/**
 * 路由显示信息
 * 
 */
@Data
public class MetaVo {
	/**
	 * 设置该路由在侧边栏和面包屑中展示的名字
	 */
	private String title;

	/**
	 * 设置该路由的图标，对应路径src/assets/icons/svg
	 */
	private String icon;

	/**
	 * 设置为true，则不会被 <keep-alive>缓存
	 */
	//private boolean noCache;

	/**
	 * 内链地址（http(s)://开头）
	 */
	//private String link;

	@JsonProperty(value = "isKeepAlive")
	private boolean isKeepAlive;// 是否缓存isCache

	@JsonProperty(value = "isHide")
	private boolean isHide;// 是否隐藏visible

	@JsonProperty(value = "isIframe")
	private boolean isIframe;// 是否内嵌isFrame

	@JsonProperty(value = "isLink")
	private String isLink;// 链接地址link

	@JsonProperty(value = "isAffix")
	private boolean isAffix;// 是否固定isAffix

	public MetaVo() {
	}

	public MetaVo(String title, String icon) {
		this.title = title;
		this.icon = icon;
	}

//	public MetaVo(String title, String icon) {
//		this.title = title;
//		this.icon = icon;
//		this.noCache = noCache;
//	}

//	public MetaVo(String title, String icon, String link) {
//		this.title = title;
//		this.icon = icon;
//		this.link = link;
//	}

//	public MetaVo(String title, String icon, boolean noCache, String link) {
//		this.title = title;
//		this.icon = icon;
//		this.noCache = noCache;
//		if (StringUtils.ishttp(link)) {
//			this.link = link;
//		}
//	}

	public MetaVo(SysMenu menu) {
		// menu.getMenuName(), menu.getIcon(), StringUtils.equals("1",
		// menu.getIsCache()), menu.getPath())
		this.title = menu.getMenuName();
		this.icon = menu.getIcon();
		if (menu.getIsCache() != null) {
			this.isKeepAlive = menu.getIsCache() == 1;
		}

		if (StringUtils.ishttp(menu.getPath())) {
			this.isLink = menu.getPath();
		}

		this.isHide = menu.getVisible()==0;

		if (menu.getIsFrame() != null) {
			this.isIframe = menu.getIsFrame() == 1;
		}

		if (menu.getIsAffix() != null) {
			this.isAffix = menu.getIsAffix() ==1;
		}
	}
}
